'''
Created on 2010-11-25

@author: kenny
'''
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t -*-
from yapsy.PluginManager import PluginManager
import sys
import getopt

class parseInput:
    
    def __init__(self,argv):
        self.argv=argv
        self.pluginName=None
        self.rval=None
    def usage(self):
        print "KZTools Help:\n"
    
    def parseFlags(self):
        try:
            opts,args=getopt.getopt(self.argv,"c:",["char2ascii="])
        except getopt.GetoptError:
            self.usage()
            sys.exit(2)
        for opt,arg in opts:
            if opt in ("-c","--char2ascii"):
                self.pluginName="char2ascii"
                self.rval=arg
        
        if len(args) != 0:
            self.usage()
            sys.exit(2)
        if self.rval == None:
            self.usage()
            sys.exit(2)
        return self.rval 
        
class KZTools:
    """
    this is a tool kit of kenneth zhou
    """
    def __init__(self):
        print "KZTools Init"

        self.simplePluginManager = PluginManager()
        self.simplePluginManager.setPluginPlaces(["plugins"])
        self.simplePluginManager.collectPlugins()
        for pluginInfo in self.simplePluginManager.getAllPlugins():
            self.simplePluginManager.activatePluginByName(pluginInfo.name)
     
    def callFunction(self,pluginName,args):
        plugin = self.simplePluginManager.getPluginByName(pluginName)
        plugin.plugin_object.run(args)

if __name__ == '__main__':
    pi=parseInput(sys.argv[1:])
    args=pi.parseFlags()
    kztools=KZTools()
    kztools.callFunction(pi.pluginName, args)
    